package
{
	import com.Controller;
	import com.Data;
	import com.Lang;
	import com.View;
	import com.assist.Helper;
	import com.assist.URI;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	public class Main extends Sprite
	{
		public static var Instance:Main;
		
		private var _ctrl :Controller;
		private var _data :Data;
		private var _view :View;
		private var _lang :Lang;
		
		public function Main()
		{
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		protected function addedToStage(event:Event) : void {
			var e:* = event;
			Instance = this;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			URI.test = Config.EnableDomainSelector;
			URI.analyze(this);
			Helper.test = Config.EnableProtocolHelper;
			Helper.initStage(stage);
			_data = new Data();
			_ctrl = new Controller();
			_view = new View(stage);
			_lang = new Lang();
			_data.onConnect = function () : void
			{
				Helper.backtrace("connected");
				_view.show();
			}
			
			_view.init(_data, _ctrl, _lang);
			_ctrl.init(_data, _lang);
			_data.init(_view, _ctrl);
			Helper.backtrace("init");
		}
	}
}